package ad.common
{
	import flash.external.ExternalInterface;
	
	/**
	 * applyDeflexion
	 * @version ActionScript 3.0
	 * @author Adrian C. Miranda
	 * @mail ad@adrianmiranda.com.br
	 */
	public function applyDeflexion(localPath:String = '../', browserPath:String = ''):String
	{
		var protocol:String, hostname:String, port:String, pathname:String, filepath:String;
		if (ExternalInterface.available)
		{
			protocol = ExternalInterface.call('window.location.protocol.toString');
			hostname = ExternalInterface.call('window.location.hostname.toString');
			port = ExternalInterface.call('window.location.port.toString');
			pathname = ExternalInterface.call('window.location.pathname.toString');
		}
		port = (port) ? ':' + port : '';
		filepath = (protocol && protocol.substr(0, 4) != 'http') ? browserPath : localPath;
		return(protocol && hostname && pathname ? protocol + '//' + hostname + port + pathname + browserPath : filepath);
	}
}